// 导入request.js异步请求工具 
import request from '@/utils/request.js'

//提供调用注册接口的函数
export const userRegisterService = (registerData) => {
    //借助UrlSearchParams 完成传递
    const param = new URLSearchParams();
    for(let key in registerData){
        param.append(key,registerData[key])
    }
    return request.post('/user/reg',param)
}



//提供调用登入接口的函数
export const userLoginService = (loginData) => {
    //借助UrlSearchParams 完成传递
    const param = new URLSearchParams();
    for(let key in loginData){
        param.append(key,loginData[key])
    }
   return request.post('/user/login',param)
}



//获取用户详细信息
export const userInfoService = () => {
    return request.get('/user/userinfo')
}

//修改个人信息
export const userInfoUpdateService = (userInfoData) => {
    return request.put('/user/update',userInfoData)
    
}

//修改用户头像
export const userAvatarUpdateService = (avatarUrl) => {

    // '/user/updateAvatar?avatarUrl='+avatarUrl ：这种写法 等价于  new URLSearchParams();
    return request.patch('/user/updateAvatar?avatarUrl='+avatarUrl)
}


//修改密码
export const userUpdatePasswordService = (passwordData) => {
    //request.patch : 异步请求局部修改
    // const params = new URLSearchParams();
    // for(let key in passwordData){
    //     params.append(key,passwordData[key])
    // }
    return request.patch('/user/updatePwd',passwordData)
}


